
var Util = {
    //Ajax get请求
    get:function (url, data){
        let urlParam = url;
        if (data){
            urlParam = urlParam + '?' + this.formatParam(data);
        }

        return $.ajax({
            url: urlParam,
            type: 'GET',
            dataType : 'json'
        })
    },
    //Ajax post请求
    postForm:function (url, data){
        return $.ajax({
            url: url,
            type: 'POST',
            data : data,
            dataType : 'json',
            contentType : 'application/x-www-form-urlencoded;charset=UTF-8'
        })
    },
    postJSON:function (url,data){
        return $.ajax({
            url: url,
            type: 'POST',
            data : JSON.stringify(data),
            dataType : 'json',
            contentType : 'application/json;charset=UTF-8'
        })
    },

    //格式化URL后面的参数
    formatParam:function (param){
        let urlParam = '';
        for (var key in param) {
            urlParam += `${key}=${query[key]}&`
        }
        // 去除最后多余的那一个&
        urlParam = urlParam.slice(0, -1);
        return urlParam;
    }
}